import tkinter
def class_start():
    label.config(text="大数据班上课")
def class_end():
    label.config(text="大数据班下课")
def lecture(i):
    label.config(text=f"正在讲课{i}")
root = tkinter.Tk()
root.geometry("550x600")
root.title("课程展示")
label = tkinter.Label(root, text="付老师课堂")
label.grid(row=0, column=0, columnspan=8)  # 使用grid布局，跨越8列
button1 = tkinter.Button(root, text="上课",
                         command=class_start,
                         width=7, height=1)
button1.grid(row=1, column=0)
button2 = tkinter.Button(root, text="下课",
                         command=class_end,
                         width=7, height=1)
button2.grid(row=1, column=7)
# 创建讲课按钮，使用grid布局分成两列
for i in range(1, 33):
    row = (i - 1) // 8 + 2  # 计算行号，从第3行开始，每8个按钮换一行
    col = (i - 1) % 8
    button = tkinter.Button(root, text=f"讲课{i}",
                            command=lambda num=i: lecture(num),
                            width=7, height=1)
    button.grid(row=row, column=col, padx=5, pady=5)
root.mainloop()